home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / v3_1 / sbp3_1e.lzh / MENUDEMO.PL < prev    next >
Text File  |  1991-11-01  |  1KB  |  61 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5.  
  6. /* MENUDEMO.PL */
  7. /* Illustrates accepting input from a menu */
  8.  
  9. /*
  10.  *  Main routine, called by the starting query
  11.  */
  12.  
  13. main_program :-  display_menu,
  14.          get_from_menu(State),
  15.          capital_of(State,City),
  16.          nl,
  17.          write('The capital of '),
  18.          write(State),
  19.          write(' is '),
  20.          write(City),
  21.          nl.
  22.  
  23. /*
  24.  *  The knowledge base
  25.  */
  26.  
  27. capital_of(georgia,atlanta).
  28. capital_of(california,sacramento).
  29. capital_of(florida,tallahassee).
  30. capital_of(connecticut,hartford).
  31.  
  32. /*
  33.  *  Routines to display the menu
  34.  */
  35.  
  36. display_menu :- write('Which state do you want to know about?'),nl,
  37.         write(' 1  Georgia'),nl,
  38.         write(' 2  California'),nl,
  39.         write(' 3  Florida'),nl,
  40.         write(' 4  Connecticut'),nl,
  41.         write('Type a number, 1 to 4 -- ').
  42.  
  43. /*
  44.  *  Routine to accept user's choice from menu
  45.  */
  46.  
  47. get_from_menu(State) :-  get(Code),
  48.              interpret(Code,State).
  49.  
  50. interpret(49,georgia).      /* ASCII 49 = '1' */
  51. interpret(50,california).   /* ASCII 50 = '2' */
  52. interpret(51,florida).      /* ASCII 51 = '3' */
  53. interpret(52,connecticut).  /* ASCII 52 = '4' */
  54.  
  55. /*
  56.  *  Starting query
  57.  */
  58.  
  59. start :- main_program.
  60.  
  61.